//
//  AppDelegate.m
//  SerialPort
//
//  Created by Viking Lai on 2018/5/25.
//  Copyright © 2018年 Viking Lai. All rights reserved.
//

#import "AppDelegate.h"
#import "SerialPort.h"
@interface AppDelegate ()
{
    SerialPort *serialPort;
}

@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    serialPort = [[SerialPort alloc]init];
    [self OpenDevice];
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

- (void)OpenDevice
{
    [serialPort open:@"/dev/cu.usbserial-A906E2F1" baudrate:115200 databits:8 stopbits:1 parity:0 flowControls:0];
    
    return;
}

- (IBAction)startBtn:(NSButton *)sender {
    [serialPort readExisting];
    [NSThread sleepForTimeInterval:0.5];
    [serialPort write:@"help\n"];
    [NSThread sleepForTimeInterval:0.5];
    NSString *string = [serialPort readExisting];
    NSLog(@"%@",string);
}

@end
